var utils = require('../../../utils/util.js');
var c = require('../../../utils/config.js');
Page({
    data: {
        bill_nav: [
            '收入记录',
            '支出记录'
        ],
        total_name:'总收入',
        total_money:0,
        select: 0,
        filter_nav: [
            '全部',
            '充值',
            '提现',
            '消费',
            '系统加钱',
            '系统减钱',
            '收益转入到余额',
            '订单退款',
            '驳回提现',
            '升级',
        ],
        ym:'',
        status:1,
        type:0,
        select2: 0,
        filterH: 0,
        cutover: false,
        lists: []
    },
    onShow: function () {
        utils.checkLogin();
        this.getList();
    },
    //下拉刷新
    // onPullDownRefresh: function () {
    //     this.setData({
    //       lists: [],
    //       ym:'',
    //     });
    //     this.getList();
    // },
    // //上拉加载
    // onReachBottom: function () {
    //     this.setData({
    //       lists: [],
    //       ym:'',
    //     });
    //     this.getList();
    // },

    getList:function(){
        var that = this;
        var token = wx.getStorageSync("userinfo").wap_token;
        var data = {
            url:"/yluser/userbill/lists",
            token:token,
            ym:this.data.ym,
            type:this.data.type,
            status:this.data.status,
        };
        utils.request(data).then(function(res){
            if (res.code == 0) {
                var data = res.data.list
                var total = parseFloat(0);
                data.forEach((item, index) => {
                    total += parseFloat(item.money);
                });
                that.setData({
                    lists:data,
                    ym:res.data.ym,
                    total_money:total.toFixed(2)
                });
                wx.stopPullDownRefresh();
            }
        });
    },

    select_nav: function (e) {
        let k = e.currentTarget.dataset.index;
        // 0 |收入  1 |支出
        var value = 0;
        var total_name='';
        switch(k){
            case 0:
                value = 1;
                total_name = '总收入';
                break;
            case 1:
                value = -1;
                total_name = '总支出';
                break;
            default:
                value = 0;
                total_name = '总收入';
                break;
        }
        this.setData({
            select: k,
            status:value,
            total_name:total_name,
            ym:'',
            type:0
        })
        this.getList();
    },
    filter_tab: function (e) {
        let k = e.currentTarget.dataset.index;
        var value = 0;
        switch(k){
            case 0:
                value = 0;
                break;
            case 1:
                value = 100;
                break;
            case 2:
                value = 202;
                break;
            case 3:
                value = 200;
                break;
            case 4:
                value = 101;
                break;
            case 5:
                value = 201;
                break;
            case 6:
                value = 207;
                break;
            case 7:
                value = 111;
                break;
            case 8:
                value = 106;
                break;
            case 9:
                value = 203;
                break;
            default:
                value = 0;
                break;
        }
        this.setData({
            select2: k,
            type:value,
            ym:'',
            cutover:false
        })
        this.getList();
    },
    openfilter: function () {
        let cutover = this.data.cutover
        this.setData({
            cutover: !cutover
        })
        if (cutover == true) {
            this.setData({
                filterH: 0
            })
        } else {
            this.scroll_distance()

        }
    },
    scroll_distance: function () {
        this.setData({
            filterH: 130
        })
    },
    bindDateChange: function (e) {
        //console.log('picker发送选择改变，携带值为', e.detail.value)
        this.setData({
            ym: e.detail.value
        })
        this.getList();
    }
})